﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ParamSetCollection.General.ParamTable;

namespace MainController.Hardware.PLC.MEGMEET.Datas
{
    class JTRAddressHelper
    {

        public static void SortParams(TableUnit tableData)
        {
            SortCTX(tableData.ctxParam);
            SortSV(tableData.svParam);
            SortPV(tableData.pvParam);
            SortInput(tableData.inputParam);
            SortOutput(tableData.outputParam);
            SortAlarm(tableData.alarmsHelper.alarmGroup);

        }

        private static void SortCTX(TableGroup tg)
        {
            int addr = 13000;
            List<string> keys = tg.shortParamDic.Keys.ToList();
            for (int i = 0; i < keys.Count; i++)
            {
                tg.shortParamDic[keys[i]].Position = addr.ToString();
                addr++;
            }

            addr = 13023;
            keys = tg.dwParamDic.Keys.ToList();
            for (int i = 0; i < keys.Count; i++)
            {
                tg.dwParamDic[keys[i]].Position = addr.ToString();
                addr = addr + 2;

            }

        }
        private static void SortSV(TableGroup tg)
        {
            int addr = 13100;
            List<string> keys = tg.shortParamDic.Keys.ToList();
            for (int i = 0; i < keys.Count; i++)
            {
                if(keys[i]== "Zone1UpperTempOffsetSV")
                {
                    addr = 13160;
                }
                else if(keys[i]== "Zone1UpperPValueSV")
                {
                    addr = 13220;
                }
                else if (keys[i] == "FanInvertor1FreqSV")
                {
                    addr = 13330;
                }
                else if (keys[i] == "PCBCountMaxAlertSV")
                {
                    addr = 13365;
                }
                else if (keys[i] == "NitroPreheatTempOffsetSV")
                {
                    addr = 13399;
                }

                tg.shortParamDic[keys[i]].Position = addr.ToString();
                addr++;
            }


            addr = 13550;
            keys = tg.dwParamDic.Keys.ToList();
            for (int i = 0; i < keys.Count; i++)
            {
                tg.dwParamDic[keys[i]].Position = addr.ToString();
                addr = addr + 2;

            }




        }
        private static void SortPV(TableGroup tg)
        {

        }
        private static void SortInput(TableGroup tg)
        {

        }
        private static void SortOutput(TableGroup tg)
        {

        }
        private static void SortAlarm(TableGroup tg)
        {

        }


    }
}
